﻿using Coway.Ordering.Buyers;
using Coway.Ordering.Orders;
using Coway.Ordering.PayOrders;
using Coway.Ordering.Products;
using Coway.Ordering.Sellers;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace Coway.Ordering.EntityFrameworkCore
{
    public static class OrderingDbContextModelCreatingExtensions
    {
        public static void ConfigureOrdering(this ModelBuilder builder)
        {
            Check.NotNull(builder, nameof(builder));

            builder.Entity<Product>(b =>
            {
                b.ToTable(OrderingConsts.DbTablePrefix + "Product", OrderingConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<Order>(b =>
            {
                b.ToTable(OrderingConsts.DbTablePrefix + "Order",
                          OrderingConsts.DbSchema);
                b.ConfigureByConvention(); //auto configure for the base class props
                //b.Property(x => x.Name).IsRequired().HasMaxLength(128);
            });

            builder.Entity<OrderItem>(b =>
            {
                b.ToTable(OrderingConsts.DbTablePrefix + "OrderItem", OrderingConsts.DbSchema);
                b.ConfigureByConvention();
                /* Configure more properties here */
                //b.Property(x => x.TotalPrice).HasColumnType("decimal(20,8)");
                //b.Property(x => x.TotalDiscount).HasColumnType("decimal(20,8)");
                //b.Property(x => x.ActualTotalPrice).HasColumnType("decimal(20,8)");
                //b.Property(x => x.UnitPrice).HasColumnType("decimal(20,8)");
                //b.Property(x => x.RefundAmount).HasColumnType("decimal(20,8)");
            });

            builder.Entity<Buyer>(b =>
            {
                b.ToTable(OrderingConsts.DbTablePrefix + "Buyer", OrderingConsts.DbSchema);
                b.ConfigureByConvention();
                /* Configure more properties here */
                //b.Property(x => x.TotalPrice).HasColumnType("decimal(20,8)");
                //b.Property(x => x.TotalDiscount).HasColumnType("decimal(20,8)");
                //b.Property(x => x.ActualTotalPrice).HasColumnType("decimal(20,8)");
                //b.Property(x => x.UnitPrice).HasColumnType("decimal(20,8)");
                //b.Property(x => x.RefundAmount).HasColumnType("decimal(20,8)");
            });

            builder.Entity<Seller>(b =>
            {
                b.ToTable(OrderingConsts.DbTablePrefix + "Seller", OrderingConsts.DbSchema);
                b.ConfigureByConvention();
                /* Configure more properties here */
                b.Property(x => x.Code).HasMaxLength(64);
                //b.Property(x => x.TotalDiscount).HasColumnType("decimal(20,8)");
                //b.Property(x => x.ActualTotalPrice).HasColumnType("decimal(20,8)");
                //b.Property(x => x.UnitPrice).HasColumnType("decimal(20,8)");
                //b.Property(x => x.RefundAmount).HasColumnType("decimal(20,8)");
            });

            builder.Entity<InstallationInfo>(b =>
            {
                b.ToTable(OrderingConsts.DbTablePrefix + "InstallationInfo", OrderingConsts.DbSchema);
                b.ConfigureByConvention();
                /* Configure more properties here */
                //b.Property(x => x.Code).HasMaxLength(64);
                //b.Property(x => x.TotalDiscount).HasColumnType("decimal(20,8)");
                //b.Property(x => x.ActualTotalPrice).HasColumnType("decimal(20,8)");
                //b.Property(x => x.UnitPrice).HasColumnType("decimal(20,8)");
                //b.Property(x => x.RefundAmount).HasColumnType("decimal(20,8)");
            });

            builder.Entity<CCRPayOrder>(b =>
            {
                b.ToTable(OrderingConsts.DbTablePrefix + "CCRPayOrder", OrderingConsts.DbSchema);
                b.ConfigureByConvention();
            });

            builder.Entity<ACHPayOrder>(b =>
            {
                b.ToTable(OrderingConsts.DbTablePrefix + "ACHPayOrder", OrderingConsts.DbSchema);
                b.ConfigureByConvention();
            });
        }
    }
}